package com.zzyl.nursing.controller.member;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusResponseBody;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.FamilyMemberElderDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.DeviceDataGraphVo;
import com.zzyl.nursing.vo.FamilyMemberElderVo;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.MemberElderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author alexis
 * @date 2025-01-09
 */
@Api(tags = "老人家属管理")
@RestController
@RequestMapping("/member/user")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private IFamilyMemberElderService familyMemberElderService;

    @PostMapping("/login")
    public R<LoginVo> login(@RequestBody UserLoginRequestDto userLoginRequestDto) {
        // 调用Service层接口进行小程序登录
        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
        return R.ok(loginVo);
    }


    /**
     * 绑定家人
     */
    @PostMapping("/add")
    public AjaxResult bindingFamilyMember(@RequestBody FamilyMemberElderDto familyMemberElderDto)  {
        return toAjax(familyMemberElderService.bindingFamilyMember(familyMemberElderDto));
    }

    /**
     * 查询家人列表
     */
    @GetMapping("/my")
    public AjaxResult getMyFamilyMember() {
        List<FamilyMemberElderVo> list = familyMemberElderService.getMyFamilyMember();
        return success(list);
    }

    /**
     * 分页查询已绑定家人列表
     */
    @GetMapping("/list-by-page")
    public AjaxResult listByPage() {
        List<MemberElderVo> list = familyMemberElderService.listByPage();
        return success(list);
    }

    /**
     * 查询健康数据
     */
    @PostMapping("/QueryDevicePropertyStatus")
    public AjaxResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) {
        QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData result
                = familyMemberService.queryDevicePropertyStatus(request);
        return success(result);
    }

    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(@ApiParam(value = "物联网设备id") @RequestParam("iotId") String iotId,
                                               @ApiParam(value = "功能ID") @RequestParam("functionId") String functionId,
                                               @ApiParam(value = "开始时间，传入指定日期的0点对应时间戳") @RequestParam("startTime") Long startTime,
                                               @ApiParam(value = "结束时间，传入指定日期的23:59:59对应时间戳") @RequestParam("endTime") Long endTime) {

        List<DeviceDataGraphVo> list = familyMemberService.queryDeviceDataListByDay(iotId, functionId, startTime, endTime);
        return success(list);
    }

    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(@ApiParam(value = "物联网设备id") @RequestParam("iotId") String iotId,
                                                @ApiParam(value = "功能ID") @RequestParam("functionId") String functionId,
                                                @ApiParam(value = "开始时间，传入指定日期的0点对应时间戳") @RequestParam("startTime") Long startTime,
                                                @ApiParam(value = "结束时间，传入指定日期的23:59:59对应时间戳") @RequestParam("endTime") Long endTime) {

        List<DeviceDataGraphVo> list = familyMemberService.queryDeviceDataListByWeek(iotId, functionId, startTime, endTime);
        return success(list);
    }
}
